from apps.Model.yolo.bird_predict import main as predict
import sys


# 定义图片检测器
def image_detect(image_path):
    bird_dict = {
        'Black_footed_Albatross': '黑脚信天翁',
        'Laysan_Albatross': '黑背信天翁',
        'Sooty_Albatross': '乌信天翁',
        'Groove_billed_Ani': '沟嘴犀鹃',
        'Crested_Auklet': '凤头海雀',
        'Least_Auklet': '小海雀',
        'Parakeet_Auklet': '白腹海鹦',
        'Rhinoceros_Auklet': '角嘴海雀',
        'Brewer_Blackbird': '蓝头黑鹂',
        'Red_winged_Blackbird': '红翅黑鹂',
        'Rusty_Blackbird': '锈色黑鹂',
        'Yellow_headed_Blackbird': '黄头黑鹂',
        'Bobolink': '食米鸟',
        'Indigo_Bunting': '靛蓝鹀',
        'Lazuli_Bunting': '白腹蓝彩鹀',
        'Painted_Bunting': '丽色彩鹀',
        'Cardinal': '红衣凤头鸟',
        'Spotted_Catbird': '点斑园丁鸟',
        'Gray_Catbird': '灰嘲鸫',
        'Yellow_breasted_Chat': '黄胸大䳭莺',
        'Eastern_Towhee': '东方雀鹀',
        'Chuck_will_Widow': '卡氏夜鹰',
        'Brandt_Cormorant': '加州鸬鹚',
        'Red_faced_Cormorant': '红脸鸬鹚',
        'Pelagic_Cormorant': '海鸬鹚',
        'Bronzed_Cowbird': '铜色牛鹂',
        'Shiny_Cowbird': '紫辉牛鹂',
        'Brown_Creeper': '褐旋木雀',
        'American_Crow': '美洲乌鸦',
        'Fish_Crow': '鱼鸦',
        'Black_billed_Cuckoo': '黑嘴杜鹃',
        'Mangrove_Cuckoo': '红树美洲鹃',
        'Yellow_billed_Cuckoo': '黄嘴杜鹃',
        'Gray_crowned_Rosy_Finch': '灰冠玫瑰雀',
        'Purple_Finch': '紫红朱雀',
        'Northern_Flicker': '北扑翅䴕',
        'Acadian_Flycatcher': '阿卡迪亚捕蝇鸟',
        'Great_Crested_Flycatcher': '大冠鹟',
        'Least_Flycatcher': '小鹟',
        'Olive_sided_Flycatcher': '橄榄侧鹟',
        'Scissor_tailed_Flycatcher': '剪翅鹟',
        'Vermilion_Flycatcher': '朱红鹟',
        'Yellow_bellied_Flycatcher': '黄腹鹟',
        'Frigatebird': '军舰鸟',
        'Northern_Fulmar': '北风鸦',
        'Gadwall': '赤膀鸭',
        'American_Goldfinch': '美洲金翅雀',
        'European_Goldfinch': '欧洲金翅雀',
        'Boat_tailed_Grackle': '船尾椋鸟',
        'Eared_Grebe': '角䴙䴘',
        'Horned_Grebe': '长菊头鹬',
        'Pied_billed_Grebe': '枕菊部䴙䴘',
        'Western_Grebe': '西部䴙䴘',
        'Blue_Grosbeak': '蓝色蜡嘴鸟',
        'Evening_Grosbeak': '黄腹蜡嘴鸟',
        'Pine_Grosbeak': '松蜡嘴鸟',
        'Rose_breasted_Grosbeak': '玫瑰胸蜡嘴鸟',
        'Pigeon_Guillemot': '鸽鸽鸥',
        'California_Gull': '加州鸥',
        'Glaucous_winged_Gull': '冰翼鸥',
        'Heermann_Gull': '黑脚鸥',
        'Herring_Gull': '银鸥',
        'Ivory_Gull': '象牙鸥',
        'Ring_billed_Gull': '环嘴鸥',
        'Slaty_backed_Gull': '板翼鸥',
        'Western_Gull': '西部鸥',
        'Anna_Hummingbird': '安娜蜂鸟',
        'Ruby_throated_Hummingbird': '红喉蜂鸟',
        'Rufous_Hummingbird': '棕蜂鸟',
        'Green_Violetear': '绿紫耳',
        'Long_tailed_Jaeger': '长尾贼鹰',
        'Pomarine_Jaeger': '庞巴利贼鹰',
        'Blue_Jay': '蓝鸦',
        'Florida_Jay': '佛罗里达鸦',
        'Green_Jay': '绿鸦',
        'Dark_eyed_Junco': '暗眼灯草鹀',
        'Tropical_Kingbird': '热带王鹟',
        'Gray_Kingbird': '灰王鹟',
        'Belted_Kingfisher': '环带翠鸟',
        'Green_Kingfisher': '绿翠鸟',
        'Pied_Kingfisher': '派群翠鸟',
        'Ringed_Kingfisher': '环颈翠鸟',
        'White_breasted_Kingfisher': '白胸翠鸟',
        'Red_legged_Kittiwake': '红腿三趾鸥',
        'Horned_Lark': '角百灵',
        'Pacific_Loon': '太平洋潜鸟',
        'Mallard': '绿头鸭',
        'Western_Meadowlark': '西部草地百灵',
        'Hooded_Merganser': '冠秋沙鸭',
        'Red_breasted_Merganser': '赤胸秋沙鸭',
        'Mockingbird': '知更鸟',
        'Nighthawk': '夜鹰',
        'Clark_Nutcracker': '克拉克的花栗鼠',
        'White_breasted_Nuthatch': '白胸鳾',
        'Baltimore_Oriole': '巴尔的摩椋鸟',
        'Hooded_Oriole': '头巾椋鸟',
        'Orchard_Oriole': '果园椋鸟',
        'Scott_Oriole': '斯科特椋鸟',
        'Ovenbird': '炉鹛',
        'Brown_Pelican': '棕鹈',
        'White_Pelican': '白鹈',
        'Western_Wood_Pewee': '西部啸喜鹊',
        'Sayornis': '赛氏啸鸫',
        'American_Pipit': '美洲鹨',
        'Whip_poor_Will': '尖嘴夜鹰',
        'Horned_Puffin': '角蒲鹫',
        'Common_Raven': '普通鸦',
        'White_necked_Raven': '白颈鸦',
        'American_Redstart': '美洲红尾鹞',
        'Geococcyx': '庚科考科克斯',
        'Loggerhead_Shrike': '红尾伯劳',
        'Great_Grey_Shrike': '大灰伯劳',
        'Baird_Sparrow': '白德麻雀',
        'Black_throated_Sparrow': '黑喉麻雀',
        'Brewer_Sparrow': '布氏麻雀',
        'Chipping_Sparrow': '尖嘴麻雀',
        'Clay_colored_Sparrow': '白腹麻雀',
        'House_Sparrow': '家麻雀',
        'Field_Sparrow': '田麻雀',
        'Fox_Sparrow': '狐麻雀',
        'Grasshopper_Sparrow': '蚱蝉麻雀',
        'Harris_Sparrow': '哈里斯麻雀',
        'Henslow_Sparrow': '亨斯洛麻雀',
        'Le_Conte_Sparrow': '勒康德麻雀',
        'Lincoln_Sparrow': '林肯麻雀',
        'Nelson_Sharp_tailed_Sparrow': '纳尔逊尖尾麻雀',
        'Savannah_Sparrow': '沙麻雀',
        'Seaside_Sparrow': '海边麻雀',
        'Song_Sparrow': '宋麻雀',
        'Tree_Sparrow': '树麻雀',
        'Vesper_Sparrow': '夜麻雀',
        'White_crowned_Sparrow': '白冠麻雀',
        'White_throated_Sparrow': '白喉麻雀',
        'Cape_Glossy_Starling': '斑点椋鸟',
        'Bank_Swallow': '崖燕',
        'Barn_Swallow': '谷仓燕',
        'Cliff_Swallow': '悬崖燕',
        'Tree_Swallow': '树燕',
        'Scarlet_Tanager': '朱雀',
        'Summer_Tanager': '夏季红雀',
        'Artic_Tern': '北极燕鸥',
        'Black_Tern': '黑燕鸥',
        'Caspian_Tern': '里海燕鸥',
        'Common_Tern': '普通燕鸥',
        'Elegant_Tern': '优雅燕鸥',
        'Forsters_Tern': '福斯特燕鸥',
        'Least_Tern': '小燕鸥',
        'Green_tailed_Towhee': '带尾鹛',
        'Brown_Thrasher': '棕色刺莺',
        'Sage_Thrasher': '鼠莺',
        'Black_capped_Vireo': '黑顶莺',
        'Blue_headed_Vireo': '蓝头莺',
        'Philadelphia_Vireo': '费城莺',
        'Red_eyed_Vireo': '红眼莺',
        'Warbling_Vireo': '唱歌莺',
        'White_eyed_Vireo': '白眼莺',
        'Yellow_throated_Vireo': '黄喉莺',
        'Bay_breasted_Warbler': '海湾胸莺',
        'Black_and_white_Warbler': '黑白莺',
        'Black_throated_Blue_Warbler': '黑喉蓝莺',
        'Blue_winged_Warbler': '蓝翅莺',
        'Canada_Warbler': '加拿大莺',
        'Cape_May_Warbler': '角胸莺',
        'Cerulean_Warbler': '天蓝莺',
        'Chestnut_sided_Warbler': '栗侧莺',
        'Golden_winged_Warbler': '金翅莺',
        'Hooded_Warbler': '兜帽莺',
        'Kentucky_Warbler': '肯塔基莺',
        'Magnolia_Warbler': '玉带莺',
        'Mourning_Warbler': '悲莺',
        'Myrtle_Warbler': '野莺',
        'Nashville_Warbler': '纳什维尔莺',
        'Orange_crowned_Warbler': '冕黄莺',
        'Palm_Warbler': '棕榈莺',
        'Pine_Warbler': '松莺',
        'Prairie_Warbler': '草原莺',
        'Prothonotary_Warbler': '金水鸟',
    }

    # 将字典中的值每个前面都加上00n，n从1开始
    bird_dict = {str(i).zfill(3) + '.' + k: v for i, (k, v) in enumerate(bird_dict.items(), 1)}
    print(bird_dict)

    path, probs, position, name = predict(image_path)
    return path, probs, position, bird_dict[name]
